package com.simpleboot1.demo.config;

import springfox.documentation.service.ApiInfo;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * @Description todo
 * @Author joy
 * @Date 2025/9/1
 */
@Configuration
@EnableSwagger2WebMvc // 注意：如果您用的是 knife4j 3.x，这个注解可能是 @EnableKnife4j
public class SwaggerConfiguration {

    @Bean(value = "defaultApi2")
    public Docket defaultApi2() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                // 分组名称，方便做接口隔离
                .groupName("测试分组")
                .select()
                // 这里指定 Controller 扫描包路径
                .apis(RequestHandlerSelectors.basePackage("com.simpleboot1.demo"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Knife4j 演示项目 API 文档")
                .description("这是一个简单的 Spring Boot 项目，集成了 Knife4j")
                .termsOfServiceUrl("http://localhost:18000/")
                .version("1.0")
                .build();
    }

}
